package TCP.oneSent;

import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
/*
* 一发一收
* tcp客户端 发送数据
* */
public class TCPClientDemo1 {
    public static void main(String[] args) throws Exception {
        System.out.println("=====客户端启动=====");
        //1、创建一个Socket对象，构造方法中指定服务器的IP地址和端口号
        Socket socket = new Socket("127.0.0.1", 8080);
        //2、获取一个输出流，使用输出流发送数据
        OutputStream os = socket.getOutputStream();
        //3、特殊数据流
        DataOutputStream dos = new DataOutputStream(os);
        dos.writeInt(100);
        dos.writeUTF("hello,TCP");
//        socket.close();

        //接收数据
        InputStream is = socket.getInputStream();
        byte[] bytes = new byte[1024];
        int len = is.read(bytes);
        System.out.println(new String(bytes,0,len));

        socket.close();
    }
}
